///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.controller.pm.transfer;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.plian.Tools.*;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.entity.pm.transfer.TransferExamine;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.token.PassToken;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.pm.transfer.ITransferExamineService;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.pm.transfer.TransferExamineVO;
//import com.plian.system.wrapper.pm.transfer.TransferExamineWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/transferexamine")
//public class TransferExamineController extends BaseController {
//
//    private ITransferExamineService transferExamineService;
//    private FileService fileService;
//    private FormWorkflowService formWorkflowService;
//
//    private TransferExamineWrapper transferExamineWrapper;
//
//    /**
//     * 详情
//     */
//    @PostMapping("/detail")
//    public ObjResult detail(@Valid @RequestBody TransferExamine transferExamine) {
//        ObjResult objResult;
//        try {
//            TransferExamine detail = transferExamineService.getOne(Condition.getQueryWrapper(transferExamine));
//            objResult = new ObjResult(CommonCode.SUCCESS);
//            if (Optional.ofNullable(detail).isPresent()) {
//                PageData pd = new PageData();
//                TransferExamineVO transferExamineVO = transferExamineWrapper.entityToVO(detail);
//                ObjectMapper mapper = new ObjectMapper();
//                String json = JSON.toJSONStringWithDateFormat(transferExamineVO, DateUtil.PATTERN_DATETIME);
//                pd.putAll(mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
//                }));
//                objResult.setPageData(pd);
//            }
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            objResult = new ObjResult(CommonCode.ERROR);
//        }
//        return objResult;
//    }
//
//
//    /**
//     * 分页
//     */
//    @PostMapping("/list")
//    public ListResult<PageData> list(@Valid @RequestBody Query query) {
//        if (query.getAscs() == null && query.getDescs() == null) {
//            query.setAscs("code");
//            query.setDescs("create_time");
//        }
//
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<TransferExamine> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new TransferExamine()), entityList
//        );
//        queryWrapper.eq("create_company_id", TokenUtil.getTokenOrgId());
//        IPage<TransferExamine> pages = transferExamineService.page(Condition.getPage(query), queryWrapper);
//
//        List<TransferExamineVO> transferExamineVOS = transferExamineWrapper.entityToVO(pages.getRecords());
//        List<PageData> pageDataList = new ArrayList<>();
//        try {
//
//            if (CollectionUtil.isNotEmpty(transferExamineVOS)) {
//                for (TransferExamineVO vo : transferExamineVOS) {
//                    PageData pd = new PageData();
//                    ObjectMapper mapper = new ObjectMapper();
//                    String json = JSON.toJSONStringWithDateFormat(vo, DateUtil.PATTERN_DATETIME);
//                    pd.putAll(mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
//                    }));
//                    pageDataList.add(pd);
//                }
//            }
//
//            ListResult<PageData> listResult = new ListResult<>(CommonCode.SUCCESS);
//            listResult.setList(pageDataList);
//            listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//            return listResult;
//
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return new ListResult<>(CommonCode.ERROR);
//        }
//    }
//
//    /**
//     * 新增或修改
//     */
//    @PostMapping("/submit")
//    public ObjResult submit(@Valid @RequestBody TransferExamineVO transferExamineVO) {
//        Boolean checkResult = false;
//
//        if (!(Optional.ofNullable(transferExamineVO.getStatus()).isPresent() && transferExamineVO.getStatus() == FormStatusConstant.STASH)) {
//            checkResult = transferExamineService.checkIsExisted(transferExamineVO.getId(), transferExamineVO.getCode());
//        }
//
//        if (checkResult) {
//            if (StringUtil.isBlank(transferExamineVO.getVersion())) {
//                transferExamineVO.setVersion("1");
//            }
//
//            if (Optional.ofNullable(transferExamineVO.getStatus()).isPresent() && transferExamineVO.getStatus() != FormStatusConstant.STASH) {
//                transferExamineVO.setFormType(String.valueOf(FormTypeConstant.CQZC_TRANSFER_EXAMINE));
//            }
//            TransferExamine transferExamine = new TransferExamine();
//            BeanUtils.copyProperties(transferExamineVO, transferExamine);
//            boolean result = transferExamineService.saveOrUpdate(transferExamine);
//            if (result) {
//                transferExamineVO.setId(transferExamine.getId());
//                List<HashMap> listDoc = transferExamineVO.getList_doc();
//                fileService.edit(transferExamine.getId().toString(), listDoc);
//            }
//
//            HashMap<String, Object> processVariable = new HashMap<>();
//            formWorkflowService.startProcessAndSimulate(String.valueOf(transferExamine.getId()),transferExamine.getFormType(),processVariable);
//
//            return result ? new ObjResult(CommonCode.SUCCESS) : new ObjResult(CommonCode.FAIL);
//        }else{
//            return new ObjResult(CommonCode.FAIL);
//        }
//    }
//
//    /**
//     * 删除
//     */
//    @PostMapping("/remove")
//    public ObjResult remove(@RequestBody PageData pd) {
//        List<String> ids = (List<String>) pd.get("ids");
//        return transferExamineService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA))) ? new ObjResult(CommonCode.SUCCESS) : new ObjResult(CommonCode.FAIL);
//    }
//
//    /**
//     * 变更
//     */
//    @PostMapping("/change")
//    public ObjResult change(@Valid @RequestBody TransferExamine transferExamine) {
//        return transferExamineService.change(transferExamine);
//    }
//
//    /**
//     * 打印
//     */
//    @GetMapping("/buildpdf/{id}")
//    @PassToken
//    public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) {
//        return FileTools.exportPdf(transferExamineService.buildpdf(id));
//    }
////    /** TODO DEL
////     * 分页
////     */
////    @PostMapping("/reportList")
////    public ListResult<PageData> reportList( @RequestBody PageData pd) {
////        return transferExamineService.reportList(pd);
////    }
//}
